package org.star.dolphin.domain;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
@Builder
public class ResponseMessage<T> {

    @Getter
    private boolean hasError;

    @Getter
    private String msg;

    @Setter
    @Getter
    private T data;

    @Getter
    private Integer code;

    public ResponseMessage(boolean hasError, String msg, T data) {
        this.hasError = hasError;
        this.msg = msg;
        this.data = data;
        if (hasError) {
            code = 1;
        } else {
            code = 0;
        }
    }

    public ResponseMessage(boolean hasError, String msg, T data, Integer code) {
        this.hasError = hasError;
        this.msg = msg;
        this.data = data;
        this.code = code;
    }

    public Boolean hasError() {
        return this.hasError;
    }

    public Boolean noError() {
        return !this.hasError;
    }

}
